package designPattern.composite
{
	import flash.errors.IllegalOperationError;

	//抽象类
	public class BaseComponent implements IBaseComponent
	{
		protected var parentNode:IBaseComponent;
		
		public function add(c:IBaseComponent):void
		{
			throw new IllegalOperationError("必须被override");
		}
		
		public function remove(c:IBaseComponent):void
		{
			throw new IllegalOperationError("必须被override");
		}
		
		public function getChild(n:int):IBaseComponent
		{
			throw new IllegalOperationError("必须被override");
			return null;
		}
		
		//设置父节点的方法声明为internal类型(父节点的add方法就能体会到)，禁止从包外设置父节点的值，父节点的值只能通过add方法加入
		internal function setParent(c:IBaseComponent):void
		{
			this.parentNode = c; 
		}
		
		internal function remParentRef():void
		{
			this.parentNode = null;
		}
		
		public function getParent():IBaseComponent
		{
			return this.parentNode;
		}
		
		/**
		 *设置为internal类型，禁止从包外判断是组件还是叶子
		 * 在组件类中override，return true
		 * 在叶子类中不必override了 
		 * @return 
		 * 
		 */		
		internal function isComposite():Boolean
		{
			return false;
		}
		
		public function operate():void
		{
			throw new IllegalOperationError("必须被override");
		}
	}
}